package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.annotation.OperationLogIgnore;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.framework.shiro.vo.LoginSysUserVO;
import com.rabbit.eap.system.dto.IdDTO;
import com.rabbit.eap.system.dto.ModifyPwdDTO;
import com.rabbit.eap.system.dto.SysUserDTO;
import com.rabbit.eap.system.entity.SysMenu;
import com.rabbit.eap.system.param.SysUserPageParam;
import com.rabbit.eap.system.service.ISysUserService;
import com.rabbit.eap.system.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysUserController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 用户信息表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysUser")
@Module("system")
@Api(value = "用户信息表API", tags = {"用户信息表"})
public class SysUserController extends BaseController {

    @Autowired
    private ISysUserService sysUserService;


    /**
     * @param sysUserDTO:sysUserDTO数据传输对象
     * @Description: 添加用户信息表
     * @methodName: saveSysUser
     * @return: ApiResult.result(flag)
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PostMapping("/saveSysUser")
    @RequiresPermissions("sys:user:add")
    @OperationLog(name = "添加用户信息表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加用户信息表", response = ApiResult.class)
    public ApiResult saveSysUser(@Validated(AddGroup.class) @RequestBody SysUserDTO sysUserDTO) throws Exception {
        ApiResult apiResult = sysUserService.saveSysUser(sysUserDTO);
        return apiResult;
    }

    /**
     * @param sysUserDTO:sysUserDTO数据传输对象
     * @Description: 修改用户信息表
     * @methodName: modifySysUser
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysUser")
    @RequiresPermissions("sys:user:edit")
    @OperationLog(name = "修改用户信息表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改用户信息表", response = ApiResult.class)
    public ApiResult modifySysUser(@Validated(UpdateGroup.class) @RequestBody SysUserDTO sysUserDTO) throws Exception {
        ApiResult apiResult = sysUserService.modifySysUser(sysUserDTO);
        return apiResult;
    }

    /**
     * @param ids:id集合
     * @Description: 删除用户信息表
     * @methodName: removeSysUser
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysUser")
    @RequiresPermissions("sys:user:remove")
    @OperationLog(name = "删除用户信息表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除用户信息表", response = ApiResult.class)
    public ApiResult removeSysUser(@RequestParam("ids") Long[] ids) throws Exception {
        ApiResult apiResult = sysUserService.removeSysUser(ids);
        return apiResult;
    }

    /**
     * @param userId: 用户ID
     * @Description: 根据Id获取用户信息表详情
     * @methodName: getSysUserInfo
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysUserInfo/{userId}")
    @RequiresPermissions("sys:user:query")
    @OperationLog(name = "用户信息表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "用户信息表详情", response = SysUserVO.class)
    public ApiResult getSysUserInfo(@PathVariable("userId") Long userId) throws Exception {
        ApiResult apiResult = sysUserService.getSysUserById(userId);
        return apiResult;
    }

    /**
     * @param sysUserPageParam
     * @Description: 用户信息表分页列表
     * @methodName: getSysUserPageList
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("getSysUserPageList")
    @RequiresPermissions("sys:user:list")
    @OperationLog(name = "用户信息表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "用户信息表分页列表", response = SysUserVO.class)
    public ApiResult getSysUserPageList( SysUserPageParam sysUserPageParam) throws Exception {
        ApiResult apiResult = sysUserService.getSysUserPageList(sysUserPageParam);
        return apiResult;
    }

    /**
     * @param idDTO: 用户id
     * @Description: 重置密码
     * @methodName: resetPwd
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/12 21:21
     * @author: rabbit
     */
    @PutMapping("resetPwd")
    @RequiresPermissions("sys:user:edit")
    @OperationLog(name = "重置密码", type = OperationLogType.OTHER)
    @ApiOperation(value = "重置密码", response = SysUserVO.class)
    public ApiResult resetPwd(@RequestBody IdDTO idDTO) {
        ApiResult apiResult = sysUserService.resetPwd(idDTO);
        return apiResult;
    }

    /**
     * @param modifyPwdDTO:
     * @Description: 修改密码
     * @methodName: modifyPwd
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/12 21:26
     * @author: rabbit
     */
    @PutMapping("modifyPwd")
    @RequiresPermissions("sys:user:edit")
    @OperationLog(name = "修改密码", type = OperationLogType.OTHER)
    @ApiOperation(value = "修改密码", response = SysUserVO.class)
    public ApiResult modiyPwd(@Validated @RequestBody ModifyPwdDTO modifyPwdDTO) {
        ApiResult apiResult = sysUserService.modifyPwd(modifyPwdDTO);
        return apiResult;
    }
    /**
     * @Description: 修改用户状态
     * @methodName: changeUserStatus
     * @param sysUserDTO:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/7/12 21:25
     * @author: rabbit
     *
     */
    @PutMapping("changeUserStatus")
    @RequiresPermissions("sys:user:edit")
    @OperationLog(name = "修改用户状态", type = OperationLogType.OTHER)
    @ApiOperation(value = "修改用户状态", response = SysUserVO.class)
    public ApiResult changeUserStatus( @RequestBody SysUserDTO sysUserDTO){
        ApiResult apiResult = sysUserService.changeUserStatus(sysUserDTO);
        return apiResult;
    }

    /**
     * @param :
     * @Description: 获取登录用户的用户相关信息
     * @methodName: info
     * @return: com.rabbit.eap.framework.common.api.ApiResult<com.rabbit.eap.framework.shiro.vo.LoginSysUserVO>
     * @date: 2020/9/22 23:09
     * @author: rabbit
     */
    @GetMapping("/info")
    @OperationLogIgnore
    @ApiOperation(value = "获取登录用户信息", notes = "获取登录用户信息", response = LoginSysUserVO.class)
    public ApiResult<LoginSysUserVO> info() {
        ApiResult<LoginSysUserVO> apiResult = sysUserService.getInfo();
        return apiResult;
    }

    /**
     * @param :
     * @Description: 获取登录用户的菜单
     * @methodName: getUserMenu
     * @return: com.rabbit.eap.framework.common.api.ApiResult<java.util.List < com.rabbit.eap.system.entity.SysMenu>>
     * @date: 2020/9/22 23:09
     * @author: rabbit
     */
    @GetMapping("/getUserMenu")
    @OperationLogIgnore
    @ApiOperation(value = "获取登录用户菜单权限", notes = "获取登录用户菜单权限")
    public ApiResult<List<SysMenu>> getUserMenu() {
        ApiResult<List<SysMenu>> apiResult = sysUserService.getUserMenu();
        return apiResult;
    }

}

